package com.qf.controller;

import com.qf.pojo.User;
import com.qf.pojo.UserAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author wbzs,
 * @date 2022/10/19,
 * @time 23:00,
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("info/{id}")
    public User findByid( Integer id){

        User user = new User();
        user.setId(id);
        user.setName("张飞");
        //需要地址信息，地址需要找地址的程序获取
        /**
         * 参数一：我们的请求地址
         * 参数二：我们期望网络请求返回的数据解析为什么类型
         * 参数三：有没有key=value格式的参数
         *
         */
        UserAddress userAddress = restTemplate.getForObject("http://localhost:11000/address/info/" + id, UserAddress.class);
        user.setUserAddress(userAddress);
        return user;

    }

}
